;(function () {

    window.changeCr = function (id) {
        if (!id) {
            return false;
        }
        // 换肤
        var changeColor = document.querySelectorAll(id);
        var lkCr = window.localStorage.getItem('lkHr');
        var lk = document.createElement('link');
        lk.rel = 'stylesheet';

        document.querySelector('head').appendChild(lk)
        lk.href = skin(lkCr);

        // 换网站图标
        if(lkCr){
            $('.favicon_index').attr('href',favicon(lkCr))
        }

        for (var i = 0; i < changeColor.length; i++) {
            changeColor[i].addEventListener('click', function() {
                var lkHf = this.getAttribute('data-skin');
                window.localStorage.setItem('lkHr', lkHf);
                lk.href = skin(lkHf);
                $('.favicon_index').attr('href',favicon(lkHf));
            }, false)
        }
    }

    function skin(val) {
        var result;

        switch (val) {
            case 'default':
                result = 'styles/app/' + val + '/default.min.css';
                break;
            case 'yellow':
                result = 'styles/app/' + val + '/yellow.min.css';
                break;
            case 'blue':
                result = 'styles/app/' + val + '/blue.min.css';
                break;
            case 'winered':
                result = 'styles/app/' + val + '/winered.min.css';
                break;
            default:
                result = '';
        }
        return result;
    }
    function favicon(val) {
        return 'favicon_' + val + '.ico';
    }
})()
